﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business.Logic;

namespace GogTasks.UserControls
{
    public partial class SyncProgressControl : UserControl, IProgressIndicator
    {
        int _increment = 20;
        int _blue = 145;
        int _redGreen = 0;

        int _x = 0; // 172
        int _y = 5;
        Size _size = new Size(28, 24);
        private Label _lastLabel;
        int _minorStep;
        public SyncProgressControl()
        {
            InitializeComponent();
            _x = SyncLabel.Right + 4;
            NextMajor();
        }

        private void NextMajor()
        {
            if (_lastLabel != null) _lastLabel.Text = String.Empty;
            Label lab = new Label();
            lab.Font = new Font(FontFamily.GenericSansSerif, 8.25F, FontStyle.Regular);
            lab.ForeColor = Color.LightBlue;
            lab.Size = _size;
            lab.Location = new Point(_x, _y);
            lab.BackColor = Color.FromArgb(_redGreen, _redGreen, _blue);
            Controls.Add(lab);
            _lastLabel = lab;
            _minorStep = 0;

            // Increment
            _blue += _increment;
            if (_blue > 255) _blue = 255;
            _redGreen += _increment;
            if (_redGreen > 255) _redGreen = 255;
            _x += lab.Width;
        }

        private void NextMinor()
        {
            if (_lastLabel != null)
            {
                _minorStep++;
                _lastLabel.Text = _minorStep.ToString();
            }
        }

        #region IProgressIndicator Members

        private delegate void SimpleDelegate();

        public void NextMajorStep()
        {
            if (!IsDisposed) Invoke(new SimpleDelegate(NextMajor));
        }

        public void NextMinorStep()
        {
            if (!IsDisposed) Invoke(new SimpleDelegate(NextMinor));
        }

        #endregion
    }
}
